//
//  GoogleAPIMapRoute.m
//  iWeather
//
//  Created by Quan Lam on 11/15/13.
//  Copyright (c) 2013 Vo Thi My Hanh (FSU1.BU19). All rights reserved.
//

#import "GoogleAPIMapRoute.h"
#import "GoogleAPIMapStep.h"
#import <GoogleMaps/GoogleMaps.h>
@implementation GoogleAPIMapRoute

-(id) initWithAPIResult: (NSDictionary*) data {
    self = [super init];
    if (self){
        self.routeContent = [NSMutableArray array];
        NSArray* steps = [[[[[data objectForKey: @"routes"] lastObject] objectForKey:@"legs"] lastObject] objectForKey:@"steps"];
        for (NSDictionary* step in steps) {
            GoogleAPIMapStep *theStep = [[GoogleAPIMapStep alloc] init];
            theStep.distance = [[[step objectForKey:@"distance"] objectForKey:@"value"] longValue];
            theStep.duration = [[[step objectForKey:@"duration"] objectForKey:@"value"] longValue];
            CLLocationCoordinate2D loc;
            loc.latitude =[[[step objectForKey:@"start_location"] objectForKey:@"lat"] doubleValue];
            loc.longitude =[[[step objectForKey:@"start_location"] objectForKey:@"lng"] doubleValue];
            theStep.startLocation = loc;
            loc.latitude =[[[step objectForKey:@"end_location"] objectForKey:@"lat"] doubleValue];
            loc.longitude =[[[step objectForKey:@"end_location"] objectForKey:@"lng"] doubleValue];
            theStep.endLocation = loc;
            theStep.travelMode = [step objectForKey:@"travel_mode"];
            theStep.htmlInstruction = [step objectForKey:@"html_instruction"];
            [self.routeContent addObject:theStep];
        }
    }
    return self;
}
@end
